<?php

/**
 * This is the model class for table "tagrem_company_widget".
 */
require_once(dirname(__FILE__).'/base/CmsWidgetBase.php');
class CmsWidget extends CmsWidgetBase
{
    public function relations(){
        return array(
            'params' => array(self::HAS_MANY,'WidgetSetting','widget_id','order' => 'setting_group'),
            'layouts' => array(self::HAS_MANY,'CmsWidgetLayout','widget_id','order'=>'id'),
        );
    }
    
    public function behaviors()
    {
        return array(
            'TimestampBehavior'=>array('class'=>'TimestampBehavior'),
        );
    }
    
    /*public function createWidgetForPage($pageWidget){
        $settings = $pageWidget->WidgetSettings;

        Yii::import($this->path, true);
        $reflectionClass = new ReflectionClass(substr(strrchr($this->path, '.'), 1));
        $config = $settings['widget'];
        foreach ($config as $property => $value)
        {
            if (!$reflectionClass->hasProperty($property) && !$reflectionClass->hasMethod('set'.ucfirst($property)))
            {
//                $config[$property] = $attr->nodeValue;
                unset($config['widget'][$property]);
                Yii::log("Unable to set value for property '{$property}'. It is possible the property is defined in the widget definition but not the widget class.");
            }
        }

        /**
        * @var BaseCmsWidget
        * /
        $widget = Yii::app()->controller->createWidget($this->path, $config);
        $widget->setPageWidgetId($pageWidget->id);
        $widget->PageId = $pageWidget->page_id;
        $widget->ContentTypeId = $pageWidget->content_type_id;
        $widget->DataSettings = $settings['data'];
        if ($widget->SelectedLayout instanceof BaseCmsWidgetLayout)
            $widget->SelectedLayout->config($settings['layout']);

        return $widget;        
    }*/
}
